const express = require('express')
const next = require('next')
const LRUCache = require('lru-cache')
const v8 = require('v8')

const port = parseInt(process.env.PORT, 10) || 80
const dev = false
const app = next({ dev })
const handle = app.getRequestHandler()

// const ssrCache = new LRUCache({
//   max: 100,
//   maxAge: 1000 * 5 //缓存时间
// })

app.prepare().then(() => {
    const server = express()

    server.get('/', (req, res) => {
        return app.render(req, res, '/index', req.query)
    })

    server.get('/test', (req, res) => {
        return app.render(req, res, '/test')
    })

    server.get('*', (req, res) => {
        return handle(req, res)
    })

    server.listen(port, (err) => {
        if (err) throw err
        console.log(new Date().getFullYear() + '年' + (new Date().getMonth() + 1) + '月' + new Date().getDate() + '日' + new Date().getHours() + '小时' + new Date().getSeconds() + '分' + new Date().getMinutes() + '秒' + new Date().getMilliseconds() + '毫秒' + '启动时间')
        console.log(`> Ready on //localhost`)
        console.log(v8.getHeapSpaceStatistics())
    })
})
